<template>
  <div id="detail">
    <x-header>详情</x-header>
    <swiper auto loop height="300px">
      <swiper-item class="swiper-demo-img" v-for="(item, index) in swipList" :key="index">
        <img :src="item.url" style="height:100%; width: 100%;">
      </swiper-item>
    </swiper>
    <div class="details">
      <div class="pro_title">
        <h2 class="title">{{productList.title}}</h2>
        <p class="price">¥{{productList.price}}</p>
        <p class="count">{{productList.count}}</p>
      </div>
    </div>
    <tab :line-width="1" active-color='#ffa534'>
      <tab-item @on-item-click='changeTab' selected>商品详情</tab-item>
      <tab-item @on-item-click='changeTab'>保养知识</tab-item>
      <tab-item @on-item-click='changeTab'>商家信息</tab-item>
    </tab>
    <div class="detailList">
      <div v-if="tab == 0">
        <div class="tabBox">
          <p>商品详情</p>
          <div class="details_box">
            <img src="assets/introduce1.jpg">
            <img src="assets/introduce2.jpg">
            <img src="assets/introduce3.jpg">
            <img src="assets/introduce4.jpg">
            <img src="assets/introduce5.jpg">
            <img src="assets/introduce6.jpg">
          </div>
        </div>
      </div>
      <div v-if="tab == 1">
        <p>保养知识</p>
      </div>
      <div v-if="tab == 2">
        <p>商家信息</p>
      </div>
    </div>
    <div class="btn_box">
      <div>
        <router-link to='/cart'>
          <img src="assets/cart_light.png">
          <badge text="0"></badge>
        </router-link>
      </div>
      <div @click="addCart">加入购物车</div>
      <button @click="buyBtn">立即购买</button>
    </div>
    <div v-transfer-dom>
      <toast v-model="showTip" text="加入购物车成功"></toast>
      <popup v-model="buy" @on-hide="log('hide')" position="bottom" @on-show="log('show')" height="50%">
        <div class="popup0">
          <div class="buySheet">
            <div class="sheetTop">
              <div class="sheetImg"><img src="assets/flower1.jpg"></div>
              <div class="goodsInfo">
                <div class="price">￥88</div>
                <div class="stock">库存98</div>
                <div class="freight">运费：
                  <span>￥12</span>
                </div>
              </div>
              <div class="close" @click="close">
                <x-icon type="ios-close" size="30"></x-icon>
              </div>
            </div>
            <div class="sheetMiddle">
              <div class="type">
                <p>请选择</p>
                <checker v-model="choose" default-item-class="check" selected-item-class="checked">
                  <checker-item v-for="(item,index) in colorList" :key="index" :value="item">{{item}}</checker-item>
                </checker>
              </div>
              <div class="number">
                <x-number title="购买数量" v-model="changeValue" :min="1" @on-change="change"></x-number>
              </div>
            </div>
            <div class="sheetBottom" @click="ensure">确定</div>
          </div>
        </div>
      </popup>
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      swipList: [
        { id: 1, url: 'assets/flower1.jpg' },
        { id: 2, url: 'assets/flower2.jpg' },
        { id: 3, url: 'assets/flower3.jpg' },
        { id: 4, url: 'assets/flower4.jpg' }
      ],
      productList: { id: 1, title: '粉色多头康乃馨', count: '10支(多头)', price: '88' },
      tab: 0,
      showTip: false,
      buy: false,
      choose: "红",
      changeValue: 1,
      details: [
        {
          index: 1, title: '粉色多头康乃馨1111', count: '10支(多头)', price: '88'
        }, {
          index: 2, title: '粉色多头康乃馨2222', count: '10支(多头)', price: '88'
        }, {
          index: 3, title: '粉色多头康乃馨3333', count: '10支(多头)', price: '88'
        }
      ],
      colorList: ["红", "黄", "白"]
    }
  },
  methods: {
    changeTab(index) {
      this.tab = index;
    },
    addCart() {
      this.showTip = true;
    },
    buyBtn() {
      this.buy = true;
    },
    log(str) {
      console.log(str)
    },
    close() {
      this.buy = false;
    },
    change(val) {
      console.log('change', val)
    },
    ensure() {
      this.buy = false;
      this.$router.push({ path: '/payment' })
    }
  },
  mounted() {

  }
}
</script>

<style lang="less">
#detail {
  .details {
    padding: 10px;
    h2 {
      font-size: 16px;
    }
    p.price {
      font-size: 14px;
      color: #ffa534;
    }
    p.count {
      font-size: 12px;
      color: #8a8a8a;
    }
  }
  .detailList {
    padding: 0 10px;
    margin-bottom: 50px;
  }
  .details_box {
    width: 100%;
    height: 100%;
    img {
      width: 100%;
    }
  }
  .btn_box {
    font-size: 14px;
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #fff;
    border-top: 2px solid #c6c6c6;
    div {
      width: 40%;
      flex-direction: row;
      color: #ffa534;
      text-align: center;
      line-height: 38px;
      border-left: 2px solid #c6c6c6;
    }
    button {
      border: none;
      background: #fff;
      width: 40%;
      flex-direction: row;
      color: #ffa534;
      text-align: center;
      line-height: 38px;
      border-left: 2px solid #c6c6c6;
    }
    img {
      width: 24px;
      height: 24px;
      position: relative;
      top: 5px;
      left: 5px;
    }
  }
  .btn_box div:first-child {
    width: 20%;
    border-left: none;
    a{
      display: inline-block;
      height: 100%;
      width: 100%;
    }
  }
}
.buySheet {
  width: 100%;
  /*height: 250px;*/
  background: #fff;
  .sheetMiddle {
    padding: 5px 10px;
    margin-bottom: 20px;
    .type {
      width: 100%;
      height: 50px;
      padding-bottom: 5px;
      border-bottom: 1px solid #e9e9e9;
      p {
        font-size: 14px;
        line-height: 24px;
      }
    }
    .number {
      .weui-cell {
        padding: 5px 0 !important;
      }
    }
  }
  .vux-x-icon {
    fill: #dcdcdc;
  }
  .sheetTop {
    display: flex;
    padding: 10px;
    font-size: 14px;
    position: relative;
    border-bottom: 1px solid #e9e9e9;
    .sheetImg {
      img {
        width: 85px;
        height: 85px;
        vertical-align: middle;
      }
    }
    .goodsInfo {
      margin-left: 10px;
      line-height: 28px;
    }
    .close {
      position: absolute;
      right: 10px;
      top: 10px;
      width: 30px;
      height: 30px;
    }
    .price,
    .freight span {
      color: #ffa534;
    }
  }
  .sheetBottom {
    width: 100%;
    height: 40px;
    text-align: center;
    line-height: 40px;
    background: #e9e9e9;
    position: absolute;
    bottom: 0;
  }
  .check {
    width: 40px;
    height: 24px;
    line-height: 24px;
    font-size: 14px;
    text-align: center;
    background-color: #ececec;
    margin-right: 6px;
  }
  .checked {
    background: #ffa534;
    color: #fff;
  }
}
.vux-popup-dialog{
  background: #fff!important;
}
</style>
